package cn.tedu.boyou.acticle.service.impl;

import cn.tedu.boyou.acticle.domain.Festival;
import cn.tedu.boyou.acticle.mapper.FestivalMapper;
import cn.tedu.boyou.acticle.service.IFestivalService;
import cn.tedu.boyou.common.query.QueryObject;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class FestivalServiceImpl implements IFestivalService{

    @Autowired
    private FestivalMapper festivalMapper;

    @Override
    public PageInfo query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo(festivalMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(Festival festival) {
        if (festival.getId() == null){
            festivalMapper.insert(festival);
        }else {
            festivalMapper.updateByPrimaryKey(festival);
        }
    }

    @Override
    public void changeStateValueById(Festival festival) {
        if (festival.getId() == null){
            throw new RuntimeException("更改节日状态时候，节日的id为空");
        }
        festivalMapper.updateStateByPrimaryKey(festival);
    }

    @Override
    public List<Festival> list() {
        return festivalMapper.selectAll();
    }
}
